package com.citrix.gs.util;

import java.io.IOException;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.DatatypeConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.io.Files;

public class ToolChecker {
    
    private static Logger logger = LoggerFactory.getLogger(ToolChecker.class);

    public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
        
        byte[] b = Files.toByteArray(Paths.get("/Users/yzhou-citrix/Perforce/beaconci/localization/LocEngineering/LocEngg-Tools/BeaconToolset_TEST/ResourceDetector/resource_detector.exe").toFile());
        byte[] hash = MessageDigest.getInstance("MD5").digest(b);
        String actual = DatatypeConverter.printHexBinary(hash);
        
        logger.info("The actual: {}", actual);
        
        byte[] check_b = Files.toByteArray(Paths.get("/soft/resource_detector.exe").toFile());
        byte[] check_hash = MessageDigest.getInstance("MD5").digest(check_b);
        String check = DatatypeConverter.printHexBinary(check_hash);
        
        logger.info("The check: {}", check);
        
        if(check.equals(actual)) {
            logger.info("The check file has been latest");
        } else {
            logger.error("The check file is not the latest");
        }
        
        //File f = null;
        //FileUtils.copyURLToFile(new URL("http://beacon-test-ci.eng.citrite.net:8080/job/ResourceDetector-Receiver_X1-RfHTML5Chrome-Rainbow/ws/tools/ResourceDetector/resource_detector.exe"), f);
        
        //logger.info(f.getAbsolutePath());
    }
}